<#assign title="Benchmark列表页面">
<#include "/admin/inc/top.html"/>
<div class="main-content" id="main-content">
    <header class="header navbar bg-white shadow">
        <div class="btn-group tool-button">
            <a id="add" class="btn btn-primary navbar-btn" href="${base!}/private/fof/benchmark/add" data-pjax><i class="fa fa-plus"></i> 新建Benchmark</a>
            <button class="btn btn-danger navbar-btn" onclick="delCheck()"><i class="fa fa-times"></i> 删除选中</button>
        </div>
        <div class="pull-right offscreen-right hidden">
            <button class="btn btn-primary navbar-btn" onclick="sublime.toggleFilter('.cd-panel')"><i
                    class="fa fa-sliders"></i> 筛选
            </button>
        </div>
    </header>
    <section class="content">
        <div class="panel-body" style="padding-top: 50px;">
            <div class="table-responsive no-border">
                <input id="unitid" type="hidden">
                <table class="table table-bordered table-striped mg-t datatable">
                    <thead>
                    <tr>
                        <th>benchmark名称</th>
                        <th>wind代码</th>
                        <th>资产/策略</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
        <!-- 删除Benchmark -->
        <div id="dialogDelete" class="modal fade bs-modal-sm" tabindex="-2" role="dialog" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title">删除Benchmark</h4>
                    </div>
                    <div class="modal-body">
                        <div class="row">
                            <div class="col-xs-12">
                                Benchmark删除后无法恢复，确定删除吗？ <br/>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
                        <button id="okDel" type="button" class="btn btn-primary" data-loading-text="正在删除...">确 定</button>
                    </div>
                </div>
            </div>
        </div>
        <!-- 删除选中Benchmark -->
        <div id="dialogDeleteCheck" class="modal fade bs-modal-lg" tabindex="-2" role="dialog" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title">删除Benchmark</h4>
                    </div>
                    <div class="modal-body">
                        <div class="row">
                            <div class="col-xs-12 mb10">
                                Benchmark删除后无法恢复，确定删除已选Benchmark吗？
                            </div>
                            <div class="col-xs-12">
                                <ul id="checkedUser" class="list-group"></ul>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
                        <button id="ok" type="button" class="btn btn-primary" data-loading-text="正在删除...">确 定</button>
                    </div>
                </div>
            </div>
        </div>
        <!-- Benchmark详情 -->
        <div id="dialogUserDetail" class="modal fade bs-modal-sm" data-autoClear tabindex="-3" role="dialog" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">

                </div>
            </div>
        </div>
    </section>
</div>
<script type="text/javascript">
    var datatable;
    function initDatatable() {
        datatable = $('.datatable').DataTable({
            "dom": '<"toolbar">frtip',
            "searching": false,
            "processing": true,
            "serverSide": true,
            "select": true,
            "ordering": true,
            "language": {
                "url": "/static/admin/js/lib/datatables/js/cn.json"
            },
            "preDrawCallback": function () {

            },
            "drawCallback": function () {

            },
            "ajax": {
                "url": "/private/fof/benchmark/data",
                "type": "post",
                "data": function (d) {
                    d.extend={};
                    return JSON.stringify(d);
                },
                "dataType": "json",
                "processData": false,
                "contentType": 'application/json;charset=UTF-8'
            },
            //"order": [[0, "desc"]],
            "order": [],
            "columns": [
                {"data": "name", "bSortable": false},
                {"data": "windCode", "bSortable": false},
                {"data": "assetStrategyName", "bSortable": false},
            ],
            "columnDefs": [
                {
                    "render": function (data, type, row) {
                        return '<div class="btn-group"><button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">' +
                                ' <i class="fa fa-fw fa-gear"></i> <span class="fa fa-fw fa-angle-down"></span></button><ul class="dropdown-menu" role="menu">' +
                                '<li><a href="/private/fof/benchmark/detail/' + row.id + '" data-toggle="modal" data-target="#dialogUserDetail">基本信息</a></li>' +
                                '<li class="divider"></li>' +
                                '<li><a href="/private/fof/benchmark/edit/' + row.id + '" data-pjax>修改信息</a></li>' +
                                '<li><a href="javascript:;" onclick="del(\'' + row.id + '\')">删除</a></li>' +
                                '</ul></div>';
                    },
                    "targets":3
                }
            ],
            "createdRow": function (row, data, rowIndex) {
                $(row).attr("data-rowId",data.id);
            }
        });
        datatable.on('click', 'tr', function () {
            $(this).toggleClass('selected');
        });
    }

    function showDetail(id){
        $("#dialogUserDetail").modal({
            remote:'/private/fof/benchmark/detail/'+id
        });
    }

    function del(ids){
        var dialog = $("#dialogDeleteCheck");
        dialog.modal("show");
        dialog.find("#ok").unbind("click");
        dialog.find("#ok").bind("click", function (event) {
            var btn = $(this);
            btn.button("loading");
            $.post("${base!}/private/fof/benchmark/delete", {ids: ids.toString()}, function (data) {
                if (data.code == 200) {
                    datatable.ajax.reload(null,false);
                } else {
                    Toast.error(data.msg);
                }
                btn.button("reset");
                dialog.modal("hide");
            }, "json");
        });
    }

    function delCheck() {
        var chks = datatable.rows('.selected').data();
        if (chks.length > 0) {
            var ids = [];
            $.each(chks, function (i, n) {
                ids.push(n.id);
            });
            del(ids);
        } else {
            Toast.warning("请先选择要删除的Benchmark！");
        }
    }

    function update(id) {
        pjaxPage('/private/fof/benchmark/edit/'+id);
    }

    $(document).ready(function () {
        initDatatable();
    });
</script>
<#include "/admin/inc/bottom.html"/>